# Windows-MCP Setup Script for dagou-cli
# This script sets up Windows-MCP integration with dagou-cli

Write-Host "🪟 Setting up Windows-MCP for dagou-cli..." -ForegroundColor Green

# Check if Python 3.13+ is installed
try {
    $pythonVersion = python --version 2>$null
    if ($pythonVersion -match "Python 3\.1[3-9]") {
        Write-Host "✅ Python $pythonVersion found" -ForegroundColor Green
    } else {
        Write-Host "❌ Python 3.13+ is required. Current: $pythonVersion" -ForegroundColor Red
        exit 1
    }
} catch {
    Write-Host "❌ Python not found. Please install Python 3.13+" -ForegroundColor Red
    exit 1
}

# Check if pip is available
try {
    pip --version | Out-Null
    Write-Host "✅ pip found" -ForegroundColor Green
} catch {
    Write-Host "❌ pip not found. Please install pip" -ForegroundColor Red
    exit 1
}

# Navigate to Windows-MCP directory
$windowsMcpPath = Join-Path $PSScriptRoot "..\mcp-servers\windows-mcp"
if (Test-Path $windowsMcpPath) {
    Set-Location $windowsMcpPath
    Write-Host "✅ Windows-MCP directory found" -ForegroundColor Green
} else {
    Write-Host "❌ Windows-MCP directory not found at $windowsMcpPath" -ForegroundColor Red
    exit 1
}

# Install dependencies
Write-Host "📦 Installing Windows-MCP dependencies..." -ForegroundColor Yellow
try {
    pip install -r requirements.txt
    Write-Host "✅ Dependencies installed successfully" -ForegroundColor Green
} catch {
    Write-Host "❌ Failed to install dependencies" -ForegroundColor Red
    exit 1
}

# Test Windows-MCP server
Write-Host "🧪 Testing Windows-MCP server..." -ForegroundColor Yellow
try {
    $testResult = python -m main --help 2>$null
    if ($LASTEXITCODE -eq 0) {
        Write-Host "✅ Windows-MCP server test passed" -ForegroundColor Green
    } else {
        Write-Host "❌ Windows-MCP server test failed" -ForegroundColor Red
        exit 1
    }
} catch {
    Write-Host "❌ Failed to test Windows-MCP server" -ForegroundColor Red
    exit 1
}

# Copy example configuration
$exampleConfig = Join-Path $PSScriptRoot "..\examples\windows-mcp-config.json"
$userSettingsPath = "$env:USERPROFILE\.gemini\settings.json"

Write-Host "📋 Configuration instructions:" -ForegroundColor Cyan
Write-Host "1. Add Windows-MCP configuration to your settings.json file:" -ForegroundColor White
Write-Host "   Location: $userSettingsPath" -ForegroundColor Gray
Write-Host "2. Example configuration available at:" -ForegroundColor White  
Write-Host "   $exampleConfig" -ForegroundColor Gray
Write-Host "3. Choose from these configuration profiles:" -ForegroundColor White
Write-Host "   - windows-mcp: Full feature set (requires confirmation)" -ForegroundColor Gray
Write-Host "   - windows-mcp-safe: Safe read-only operations (auto-approved)" -ForegroundColor Gray
Write-Host "   - windows-mcp-interactive: UI automation tools (requires confirmation)" -ForegroundColor Gray
Write-Host "   - windows-mcp-system: System-level operations (requires confirmation)" -ForegroundColor Gray

Write-Host "`n🎉 Windows-MCP setup completed successfully!" -ForegroundColor Green
Write-Host "📖 Next steps:" -ForegroundColor Cyan
Write-Host "1. Update your .gemini\settings.json with MCP server configuration" -ForegroundColor White
Write-Host "2. Restart dagou-cli" -ForegroundColor White
Write-Host "3. Test with: dagou 'help me check desktop state'" -ForegroundColor White
Write-Host "4. Use /mcp command to see available Windows automation tools" -ForegroundColor White